public class Demo12 {
    public static void main(String[] args) {
        int[][] triangle = new int[5][5];
        for (int i = 0; i < 5; i++) {
            triangle[i][0] = 1;
            triangle[i][i] = 1;
        }
        for (int i = 2; i < 5; i++) {
            for (int j = 1; j < i ; j++) {
                triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
                // 除等腰边外，中间元素等于上方两元素的和
            }
        }

        /*
        *     1
        *    1 1
        *   1 2 1
        *  1 3 3 1
        * 1 4 6 4 1
        */

        for (int i = 0; i < triangle.length; i++) {
            for (int y = 4; y > i; y--) {
                System.out.print(" ");
            }// 添加数字前空格
            for (int j = 0; j <= i; j++) {
                System.out.print(triangle[i][j] + " ");
            }
            System.out.println();
        }
    }
}
